package com.lyc.mapper;

import com.lyc.pojo.Category;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface CategoryMapper {
    // 添加新板块
    @Insert("INSERT INTO categories (name, description, icon, sort_order, status) " +
            "VALUES " +
            "(#{name}, #{description}, #{icon}, #{sortOrder}, #{status})")
    void insert(Category category);

    // 获取所有板块
    @Select("SELECT * from categories order by sort_order")
    List<Category> getAllCategories();

    // 根据ID删除板块
    @Delete("DELETE FROM categories WHERE id = #{id}")
    void deleteById(Integer id);

    // 根据ID获取板块
    @Select("select * from categories where id = #{id}")
    Category findById(Integer id);

    // 根据名称获取板块
    @Select("select * from categories where name = #{name}")
    Category findByName(String name);

    // 更新板块信息
    @Update("update categories set name = #{name}, description = #{description}, " +
            "icon = #{icon}, sort_order = #{sortOrder}, status = #{status} " +
            "where id = #{id}")
    void update(Category category);
    
    // 根据ID删除板块（与deleteById功能相同，保持接口一致）
    @Delete("DELETE FROM categories WHERE id = #{id}")
    void delete(Integer id);
}